package cn.lyjuan.payment.third.base.model.app.service;

import cn.lyjuan.base.util.SpringContextHolder;
import cn.lyjuan.payment.third.base.common.entity.app.AppRegEntity;
import cn.lyjuan.payment.third.base.common.mapper.AppRegEntityMapper;
import cn.lyjuan.payment.third.base.model.app.domain.AppModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppService
{
    @Autowired
    private AppRegEntityMapper mapper;

    /**
     * 查询
     *
     * @param id
     * @return {@code null}未找到
     */
    public AppModel query(Integer id)
    {
        AppModel app = newInstance();

        boolean exist = app.query(id);
        return exist ? app : null;
    }

    /**
     * 添加
     *
     * @param name
     * @param province
     * @param city
     * @param district
     * @param adcode
     * @param detail
     * @param tel
     * @return
     */
    public AppModel add(String name, String province, String city, String district, String adcode, String detail, String tel)
    {
        AppModel app = newInstance();

        app.add(name, province, city, district, adcode, detail, tel);

        return app;
    }

    private AppModel newInstance()
    {
        return SpringContextHolder.getBean(AppModel.class);
    }
}
